/*
 * @lc app=leetcode.cn id=1576 lang=cpp
 *
 * [1576] 替换所有的问号
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;
// @lc code=start
class Solution {
public:
    string modifyString(string s) {
        int n = s.length();
        for(int i = 0;i < n;i++) {
            if(s[i] == '?') {
                if(n == 1){
                    return "a";
                }
                if(i == 0) {
                    s[i] =  (s[i+1] == '?')? 'a':(s[i+1] + 1 - 97)%26 + 97;
                } else if(i != n-1) {
                    s[i] = (s[i-1] + 1 - 'a')%26 == (s[i+1]-'a')%26? (s[i-1] + 2 - 'a') % 26 + 97:(s[i-1] + 1 - 'a') % 26+97;
                } else {
                    s[i] = (s[i-1] + 1 - 97)%26 + 97;
                }
            }
        }
        return s;
    }
};
// @lc code=end

